package day16.pack7;


import java.io.*;

/**
 * 缓冲区
 */
public class Test {
    public static void main(String[] args) {
        File file = new File("D:\\安装文件\\mysql-installer-5.5.25.0.zip");
        if (file.exists()) {
            try (
                    // 一次性从硬盘读取50M到内存中
                    BufferedInputStream is = new BufferedInputStream(new FileInputStream(file), 1024 * 1024 * 50)
            ) {
                // 每次从内存中拿2M
                byte[] data = new byte[1024 * 1024 * 2];
                // 把读取到的字节数据放到data数组中，返回实际读取到的个数
                int len = 0;
                while ((len = is.read(data)) != -1) {
                    String str = new String(data, 0, len);
                    System.out.print(str);
                }
            } catch (FileNotFoundException e) {
                throw new RuntimeException(e);
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
        }
    }
}
